﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using KFGame;
using System;

namespace KFGame
{
    public class TotalLog
    {
        public string logtype = "total";

        KFDataFile dataFile = new KFDataFile();

        public List<string> listlabes = new List<string>();

        public List<long> listDatas = new List<long>();

        string title;


        int year;
        public TotalLog(string n)
        {
            title = n;


        }


        //加载偏移 
        public void load(int offset = 0)
        {


            DateTime t = DateTime.Now;
            dataFile.title = title;
            dataFile.type = logtype;
            dataFile.consent = title;

            string[] datas = dataFile.read();
            if (datas == null) return;
            if (datas.Length < 2) return;

            listlabes.Add(datas[0]);
            listDatas.Add(Convert.ToInt64(datas[1]));
        }

        //添加数据
        public void addDatas(long d)
        {

            if (listlabes.Count == 0)
                listlabes.Add(title);
            else
                listlabes[0] = title;

            if (listDatas.Count == 0)
                listDatas.Add(d);
            else
                listDatas[0] += d;

        }

        //保存数据
        public void save()
        {
            string[] data = new string[2];
            data[0] = string.Join("", listlabes.ToArray());
            data[1] = string.Join("", listDatas.ToArray());
            dataFile.save(data);
        }
    }
}